package com.ssm.mall.service;

import com.ssm.mall.common.Res;
import com.ssm.mall.common.ResEnum;
import com.ssm.mall.dao.UserDao;
import com.ssm.mall.dao.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService implements IUserService{
    @Autowired
    UserDao userDao;

    @Override
    public Res<User> login(String username, String password) {

        User user = userDao.login(username,password);
        return (user==null)?Res.error(ResEnum.ERROR):Res.success(ResEnum.SUCCESS,user);
    }

    @Override
    public Res registry(User user) {
        user.setRole(0);
        int result = userDao.insertSelective(user);
        return (result == 1)?Res.success():Res.error();
    }

    @Override
    public Res checkValid(String name, String type) {
        int user = userDao.checkValid(name);
        return (user > 0)?Res.success():Res.error();
    }
    //修改密码
    @Override
    public Res forgetGetQuestion(String username) {
        User user = userDao.forgetGetQuestion(username);
        return (user == null)?Res.error():Res.success(ResEnum.SUCCESS,user);
    }
}
